Attempting to Convert Byte[] into Image... but is there platform issues involved

Posted by user305535 on Stack Overflow See other posts from Stack Overflow or by user305535
Published on 2010-03-30T22:27:36Z Indexed on 2010/03/30 22:33 UTC
Read the original article Hit count: 304

Filed under:
|
|
|

Greetings,

Current, I'm attempting to develop an application that takes a Byte Array that is streamed to us from a Linux C language program across a TCPClient (stream) and reassemble it back into an image/jpg. The "sending" application was developed by a off-site developer who claims that the image reassembles back into an image without any problems or errors in his test environment (all Linux)...

However, we are not so fortunate. I (believe) we successfully get all of the data sent, storing it as a string (lets us append the stream until it is complete) and then we convert it back into a Byte[]. This appears to be working fine...

But, when we take the byte[] we get from the streaming (and our string assembly) and try to convert it into an image using the System.Drawing.Image.FromStream() we get errors.... Anyone have any idea what we're doing wrong? Or, does anyone know if this is a cross-platform issue? We're developing our app for Windows XP and C# .net, but the off-site developer did his work in c and Linux... perhaps there's some difference as to how each Operating System Coverts Images into Byte Arrays?

Anyway, here's the code for converting our received ByteArray (from the TCPClient Stream) into an image. This code works when we send an image from a test machine we built that RUNS on XP, but not from the Linux box...

       System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
       byte[] imageBytes = encoding.GetBytes(data);

       MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

       // Convert byte[] to Image
       ms.Write(imageBytes, 0, imageBytes.Length);
       System.Drawing.Image image = System.Drawing.Image.FromStream(ms, false); 
               <-- DIES here, throws a {System.ArgumentException: Parameter is not valid.} error

Any advice, suggestions, theories, or HELP would be GREATLY appreciated! Please let me know???

Best wishes all! Thanks in advance!

Greg

© Stack Overflow or respective owner

Related posts about c#

Related posts about byte